﻿$.using("a2d.core.exception.provider");

a2d.core.exception.provider.ligerui = function () {
    var processTimeout = function (ex) {
        if (ex.getTimeout() > 0) {
            setTimeout(invisibleDialog, ex.getTimeout());
        }
    };
    var invisibleDialog = function () {
        $.ligerDialog.hide();
    };
    var processWarnException = function (ex) {
        $.ligerDialog.hide();
        $.ligerDialog.warn(ex.getMessage());
    };
    var processErrorException = function (ex) {
        $.ligerDialog.hide();
        $.ligerDialog.error(ex.getMessage());
    };
    var processSuccessException = function (ex) {
        $.ligerDialog.hide();
        $.ligerDialog.success(ex.getMessage());
    };

    var exceptionHandler = function (ex) {
        var concreteHandler = null;
        switch (ex.getType()) {
            case "warn":
                concreteHandler = processWarnException;
                break;
            case "error":
                concreteHandler = processErrorException;
                break;
            case "success":
                concreteHandler = processSuccessException;
                break;
            default:
                concreteHandler = processErrorException;
                break;
        }
        concreteHandler(ex);
        processTimeout(ex);
    };

    return exceptionHandler;
};

$(document).ready(function () {
    a2d.core.events.service.subscribe("a2d.core.exception:occurred", a2d.core.exception.provider.ligerui());
});

